package com.ccll.service.impl;

import com.alibaba.fastjson.JSON;
import com.ccll.domain.po.IpAddress;
import com.ccll.service.IpService;
import com.ccll.utils.IPUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Seon
 * @date 2022/11/12 18:00
 */
@Service
public class IpServiceImpl implements IpService {

    private final String queryIpUrl = "https://ip.useragentinfo.com/json";

    @Autowired
    private IPUtil ipUtil;

    @Override
    public IpAddress getIpAddress(HttpServletRequest request) {
        String ip = ipUtil.getIp(request);
        String ipAddress = ipUtil.getIpAddress(queryIpUrl, ip);
        IpAddress parseAddress = JSON.parseObject(ipAddress, IpAddress.class);
        return parseAddress;
    }
}
